package com.codepoem.designpattern.factorymethod

import com.codepoem.designpattern.simplefactory.Operation

/**
 * 工厂模式测试方法
 */
fun main(args: Array<String>) {
    var factory:IOperationFactory
    var op:Operation
    //测试加法运算
    factory = OperationAddFactory()
    op = factory.createOperation();
    op.numberA = 1.0
    op.numberB = 2.0
    println(op.getResult())
    //测试减法运算
    factory = OperationSubFactory()
    op = factory.createOperation();
    op.numberA = 1.0
    op.numberB = 2.0
    println(op.getResult())
    //测试乘法运算
    factory = OperationMulFactory()
    op = factory.createOperation();
    op.numberA = 1.0
    op.numberB = 2.0
    println(op.getResult())
    //测试除法运算
    factory = OperationDivFactory()
    op = factory.createOperation();
    op.numberA = 1.0
    op.numberB = 2.0
    println(op.getResult())
    //测试除法运算(除数为0)
    factory = OperationDivFactory()
    op = factory.createOperation();
    op.numberA = 1.0
    op.numberB = 0.0
    println(op.getResult())
}